﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MvcApplication6.BIZ;
using MvcApplication6.Models;


namespace MvcApplication6.Controllers
{
    public class HomeController : Controller
    {
        //
        // GET: /Home/

        EventBIZ BIZ = new EventBIZ();
        MenuL1BIZ menuBIZ = new MenuL1BIZ();
        PagingBIZ pagingBIZ = new PagingBIZ();
        EventBIZ eventBIZ = new EventBIZ();
        ProductBIZ productBIZ = new ProductBIZ();
        Category_eventBIZ categoryEventBIZ = new Category_eventBIZ();
        SalePersonBIZ salePersonBIZ = new SalePersonBIZ(); 

        HomeModel homeModel = new HomeModel();
        NewModel newModel = new NewModel();
        EventModel eventModel = new EventModel();
        List<EventModel> eventListModel = new List<EventModel>();
        ProductDetailModel productDetailModel = new ProductDetailModel();


        public ActionResult Index()
        {

            homeModel.ListSalePersonModel = salePersonBIZ.SalePersonSearch();


            List<Category_eventModel> listItemCate = categoryEventBIZ.Category_eventSearch();

            List<Category_eventModel> listItemCate2 = new List<Category_eventModel>();

            foreach (var catergoryEvent in listItemCate)
            {
                catergoryEvent.listEventModel = BIZ.EventSearchTitleById_ce(catergoryEvent.Id);
                listItemCate2.Add(catergoryEvent);
                
            }

            homeModel.ListCategoryEventModel = listItemCate2;

            //homeModel.EventListModel = BIZ.EventSearchTitleById_ce(2);

            //foreach(var eventItem in BIZ.EventSearchTitleById_ce(1)) {
            //    homeModel.EventListModel.Add(eventItem);
            
            //}

            homeModel.CusListModel = BIZ.EventSearchTitleById_ce(6);


            homeModel.MenuListModel = menuBIZ.GetAllMenu();
            homeModel.TotalRecord = 0;

            homeModel.ProductNewListModel = pagingBIZ.ProductSearchSale(1, 1, 8);

            homeModel.ProductSalesListModel = pagingBIZ.ProductSearchSale(1, 2, 8);

            homeModel.ProductSaleListModel = pagingBIZ.ProductSearchSale(1, 3, 8);

            homeModel.CurrentPage = 1;
            homeModel.LevelMenu = 0;
            homeModel.ProductId = 0;
                

            homeModel.SaleListModel = BIZ.EventSearchSale(1);

            homeModel.TitleMenu = "CÔNG TY TNHH TM DV KT CÔNG NGHỆ AN PHÚ";

            return View(homeModel);
        }



        [HttpGet]
        public ActionResult Paging(int? page, int LevelMenu, int Id, string TitleMenu, int Flag, int MenuId1, int MenuId2, int MenuId3)
        {
            int LevelMenu1 = LevelMenu;
            // paging product from init
            if (LevelMenu1 == 0)
            {
                 int currentPageIndex = page.HasValue ? page.Value : 1;

                homeModel.TotalRecord = pagingBIZ.ProductSearchSaleCount(Flag);

                if (homeModel.TotalRecord > 0)
                {
                    homeModel.ProductListModel = pagingBIZ.ProductSearchSale(currentPageIndex, Flag, 20);
                    homeModel.CurrentPage = currentPageIndex;
                    homeModel.LevelMenu = 0;
                    homeModel.ProductId = 0;
                    homeModel.ProductFlag = Flag;
                }

                if (Flag == 1)
                {
                    homeModel.TitleMenu = "Sản phẩm mới";
                }
                else if (Flag == 2)
                {
                    homeModel.TitleMenu = "Sản phẩm khuyến mãi";
                }
                else if (Flag == 3)
                {
                    homeModel.TitleMenu = "Sản phẩm bán chạy";
                }  

                return PartialView("_Paging", homeModel);
            
            }
            //paging product from menu
            else if (LevelMenu1 > 0 && LevelMenu1 <  4)
            {
                int PageIndex1 = page.HasValue ? page.Value : 1;
                int Id1 = Id;

                return PartialView("_Paging", GetProductFromMenu(PageIndex1, LevelMenu1, Id1, TitleMenu, MenuId1, MenuId2, MenuId3));
            
            }

            return PartialView("_Paging", homeModel);
        }

        public ActionResult DeleteProduct(int Id, int LevelMenu, int page, int IdCe, string TitleMenu, int flag, int MenuId1, int MenuId2, int MenuId3)
        {

            int checkDelete = productBIZ.ProductDelete(Id);

            if (checkDelete > 0)
            {
                int LevelMenu1 = LevelMenu;
                // paging product from init
                if (LevelMenu1 == 0)
                {
                    int currentPageIndex = page;

                    homeModel.TotalRecord = pagingBIZ.ProductSearchSaleCount(flag);

                    if (homeModel.TotalRecord > 0)
                    {
                        homeModel.ProductListModel = pagingBIZ.ProductSearchSale(currentPageIndex, flag, 20);
                        homeModel.CurrentPage = currentPageIndex;
                        homeModel.LevelMenu = 0;
                        homeModel.ProductId = 0;
                        homeModel.ProductFlag = flag;
                    }

                    if (flag == 1) {
                        homeModel.TitleMenu = "Sản phẩm mới";
                    }
                    else if (flag == 2)
                    {
                        homeModel.TitleMenu = "Sản phẩm khuyến mãi";
                    }
                    else if (flag == 3)
                    {
                        homeModel.TitleMenu = "Sản phẩm bán chạy";
                    }  
                    
                    return PartialView("_Paging", homeModel);

                }
                //paging product from menu
                else if (LevelMenu1 > 0 && LevelMenu1 < 4)
                {
                    int PageIndex1 = page;
                    int Id1 = IdCe;
                    return PartialView("_Paging", GetProductFromMenu(PageIndex1, LevelMenu1, Id1, TitleMenu, MenuId1, MenuId2, MenuId3));

                }         
            }



            return PartialView("_Paging", homeModel);
        
        }


        public ActionResult GetProductByIdL(int page, int LevelMenu, int Id, string TitleMenu, int MenuId1, int MenuId2, int MenuId3)
        {
            int PageIndex1 = page;
            int LevelMenu1 = LevelMenu;
            int Id1 = Id;
            return PartialView("_Paging", GetProductFromMenu(PageIndex1, LevelMenu1, Id1, TitleMenu, MenuId1, MenuId2, MenuId3));
        
        }
        [HttpGet]
        public ActionResult GetProductByIdL2(int page, int LevelMenu, int Ids, string TitleMenu, int MenuId1, int MenuId2, int MenuId3)
        {
            int PageIndex1 = page;
            int LevelMenu1 = LevelMenu;
            int Id1 = Ids;
            homeModel = GetProductFromMenu(PageIndex1, LevelMenu1, Id1, TitleMenu, MenuId1, MenuId2, MenuId3);

            // get thong tin cua menu ...
            homeModel.ListSalePersonModel = salePersonBIZ.SalePersonSearch();


            List<Category_eventModel> listItemCate = categoryEventBIZ.Category_eventSearch();

            List<Category_eventModel> listItemCate2 = new List<Category_eventModel>();

            foreach (var catergoryEvent in listItemCate)
            {
                catergoryEvent.listEventModel = BIZ.EventSearchTitleById_ce(catergoryEvent.Id);
                listItemCate2.Add(catergoryEvent);

            }

            homeModel.ListCategoryEventModel = listItemCate2;

            //homeModel.EventListModel = BIZ.EventSearchTitleById_ce(2);

            //foreach(var eventItem in BIZ.EventSearchTitleById_ce(1)) {
            //    homeModel.EventListModel.Add(eventItem);

            //}

            homeModel.CusListModel = BIZ.EventSearchTitleById_ce(6);


            homeModel.MenuListModel = menuBIZ.GetAllMenu();

            homeModel.SaleListModel = BIZ.EventSearchSale(1);

            return View(homeModel);

        }

        [HttpGet]
        public ActionResult ProductDetail(String ProductName, int Ids, int LevelMenu, int MenuId1, int? MenuId2, int? MenuId3)
        {

            int MenuId33 = MenuId3.HasValue ? MenuId3.Value : 0;
            int MenuId22 = MenuId2.HasValue ? MenuId2.Value : 0;
            int Id =  Ids; //int.Parse(Request.QueryString["Ids"]);
            //int LevelMenu = int.Parse(Request.QueryString["LevelMenu"]);
            //int MenuId1 = int.Parse(Request.QueryString["MenuId1"]);
            //int MenuId2 = int.Parse(Request.QueryString["MenuId2"]);
            //int MenuId3 = int.Parse(Request.QueryString["MenuId3"]);

            productDetailModel.Product = productBIZ.ProductSearchById(Id);

            productDetailModel.LevelMenu = LevelMenu;

            if (LevelMenu == 1)
            {
                productDetailModel.producListtModel = productBIZ.ProductDetailById_l(productDetailModel.Product.IdL1, LevelMenu);
            }
            else if (LevelMenu == 2)
            {
                productDetailModel.producListtModel = productBIZ.ProductDetailById_l(productDetailModel.Product.IdL2, LevelMenu);
            }
            else if (LevelMenu == 3)
            {
                productDetailModel.producListtModel = productBIZ.ProductDetailById_l(productDetailModel.Product.IdL3, LevelMenu);
            }
            else
            {
                productDetailModel.producListtModel = productBIZ.ProductDetailById_l(productDetailModel.Product.IdL3, LevelMenu);
            }

            productDetailModel.MenuId1 = MenuId1;
            productDetailModel.MenuId2 = MenuId22;
            productDetailModel.MenuId3 = MenuId33;

            homeModel.productDetailModel = productDetailModel;

            // get thong tin cua menu ...
            homeModel.ListSalePersonModel = salePersonBIZ.SalePersonSearch();


            List<Category_eventModel> listItemCate = categoryEventBIZ.Category_eventSearch();

            List<Category_eventModel> listItemCate2 = new List<Category_eventModel>();

            foreach (var catergoryEvent in listItemCate)
            {
                catergoryEvent.listEventModel = BIZ.EventSearchTitleById_ce(catergoryEvent.Id);
                listItemCate2.Add(catergoryEvent);

            }

            homeModel.ListCategoryEventModel = listItemCate2;

            //homeModel.EventListModel = BIZ.EventSearchTitleById_ce(2);

            //foreach(var eventItem in BIZ.EventSearchTitleById_ce(1)) {
            //    homeModel.EventListModel.Add(eventItem);

            //}

            homeModel.CusListModel = BIZ.EventSearchTitleById_ce(6);


            homeModel.MenuListModel = menuBIZ.GetAllMenu();

            homeModel.SaleListModel = BIZ.EventSearchSale(1);

            return View(homeModel);
        
        }



        public ActionResult ProductDetail2(int LevelMenu, int Id, int MenuId1, int MenuId2, int MenuId3)
        {
            homeModel.productDetailModel.Product = productBIZ.ProductSearchById(Id);

            homeModel.productDetailModel.LevelMenu = LevelMenu;

            if (LevelMenu == 1)
            {
                homeModel.productDetailModel.producListtModel = productBIZ.ProductDetailById_l(productDetailModel.Product.IdL1, LevelMenu);
            }
            else if (LevelMenu == 2)
            {
                homeModel.productDetailModel.producListtModel = productBIZ.ProductDetailById_l(productDetailModel.Product.IdL2, LevelMenu);
            }
            else if (LevelMenu == 3)
            {
                homeModel.productDetailModel.producListtModel = productBIZ.ProductDetailById_l(productDetailModel.Product.IdL3, LevelMenu);
            }
            else
            {
                homeModel.productDetailModel.producListtModel = productBIZ.ProductDetailById_l(productDetailModel.Product.IdL3, LevelMenu);
            }

            homeModel.productDetailModel.MenuId1 = MenuId1;
            homeModel.productDetailModel.MenuId2 = MenuId2;
            homeModel.productDetailModel.MenuId3 = MenuId3;

            // get thong tin cua menu ...
            homeModel.ListSalePersonModel = salePersonBIZ.SalePersonSearch();


            List<Category_eventModel> listItemCate = categoryEventBIZ.Category_eventSearch();

            List<Category_eventModel> listItemCate2 = new List<Category_eventModel>();

            foreach (var catergoryEvent in listItemCate)
            {
                catergoryEvent.listEventModel = BIZ.EventSearchTitleById_ce(catergoryEvent.Id);
                listItemCate2.Add(catergoryEvent);

            }

            homeModel.ListCategoryEventModel = listItemCate2;

            //homeModel.EventListModel = BIZ.EventSearchTitleById_ce(2);

            //foreach(var eventItem in BIZ.EventSearchTitleById_ce(1)) {
            //    homeModel.EventListModel.Add(eventItem);

            //}

            homeModel.CusListModel = BIZ.EventSearchTitleById_ce(6);


            homeModel.MenuListModel = menuBIZ.GetAllMenu();

            return View(homeModel);

        }

        public ActionResult IntroduceCompany(int Id)
        {

            eventModel = eventBIZ.EventSearchById(Id);

            return PartialView("_IntroduceCompany", eventModel);

        }

        public ActionResult New(int Id, int Page)
        {
            newModel.TotalRecord = pagingBIZ.EventCountPagingById_ce(Id);

            if (newModel.TotalRecord > 0 ) {
                newModel.EventListModel = pagingBIZ.EventPagingById_ce(Page ,Id);
                newModel.CurrentPage = Page;
                newModel.CategoryId = Id;
            }

            if (Id == 1 )
            {
               newModel.Title = "Tin tức sự kiện";
            
            }

            if (Id == 2 )
            {
                newModel.Title = "Dịch vụ";
            
            }

            if (Id == 8)
            {
                newModel.Title = "Đối tác";

            }

            return PartialView("_New", newModel);

        }

        public ActionResult Sale()
        {
            if (Session["checkLoginAbcuser"] == null)
            {
                eventListModel = BIZ.EventSearchSale(1);
            }else {
                eventListModel = BIZ.EventSearchSale(2);
            }

            homeModel.eventListModel = eventListModel;


            ///
            // get thong tin cua menu ...
            homeModel.ListSalePersonModel = salePersonBIZ.SalePersonSearch();


            List<Category_eventModel> listItemCate = categoryEventBIZ.Category_eventSearch();

            List<Category_eventModel> listItemCate2 = new List<Category_eventModel>();

            foreach (var catergoryEvent in listItemCate)
            {
                catergoryEvent.listEventModel = BIZ.EventSearchTitleById_ce(catergoryEvent.Id);
                listItemCate2.Add(catergoryEvent);

            }

            homeModel.ListCategoryEventModel = listItemCate2;

            //homeModel.EventListModel = BIZ.EventSearchTitleById_ce(2);

            //foreach(var eventItem in BIZ.EventSearchTitleById_ce(1)) {
            //    homeModel.EventListModel.Add(eventItem);

            //}

            homeModel.CusListModel = BIZ.EventSearchTitleById_ce(6);


            homeModel.MenuListModel = menuBIZ.GetAllMenu();

            homeModel.SaleListModel = BIZ.EventSearchSale(1);
            //return PartialView("_Sale", eventListModel);
            return View(homeModel);
        }

        public ActionResult DeleteNew(int Id, int Page, int IdCe)
        {

            int checkDelete = eventBIZ.EventDelete(Id);

            if(checkDelete > 0) {
                newModel.TotalRecord = pagingBIZ.EventCountPagingById_ce(IdCe);

                if (newModel.TotalRecord > 0)
                {
                    newModel.EventListModel = pagingBIZ.EventPagingById_ce(Page, IdCe);
                    newModel.CurrentPage = Page;
                    newModel.CategoryId = IdCe;
                }
            }

            return PartialView("_New", newModel);

        }

        public ActionResult DeleteSale(int Id)
        {

            int checkDelete = eventBIZ.EventDelete(Id);

            if (Session["checkLoginAbcuser"] == null)
            {
                eventListModel = BIZ.EventSearchSale(1);
            }
            else
            {
                eventListModel = BIZ.EventSearchSale(2);
            }

            return PartialView("_Sale", eventListModel);

        }

        public ActionResult NewDetail(string Id, string Name)
        {
            newModel.Event = eventBIZ.EventSearchById(Int32.Parse(Id));

            if (newModel.Event.IdCe != 4)
            {
                newModel.EventListModel = eventBIZ.EventSearchTitleById_ce(newModel.Event.IdCe);
            }

            homeModel.newModel = newModel;

            ///
            // get thong tin cua menu ...
            homeModel.ListSalePersonModel = salePersonBIZ.SalePersonSearch();


            List<Category_eventModel> listItemCate = categoryEventBIZ.Category_eventSearch();

            List<Category_eventModel> listItemCate2 = new List<Category_eventModel>();

            foreach (var catergoryEvent in listItemCate)
            {
                catergoryEvent.listEventModel = BIZ.EventSearchTitleById_ce(catergoryEvent.Id);
                listItemCate2.Add(catergoryEvent);

            }

            homeModel.ListCategoryEventModel = listItemCate2;

            //homeModel.EventListModel = BIZ.EventSearchTitleById_ce(2);

            //foreach(var eventItem in BIZ.EventSearchTitleById_ce(1)) {
            //    homeModel.EventListModel.Add(eventItem);

            //}

            homeModel.CusListModel = BIZ.EventSearchTitleById_ce(6);


            homeModel.MenuListModel = menuBIZ.GetAllMenu();

            homeModel.SaleListModel = BIZ.EventSearchSale(1);

            return View(homeModel);

        }





        private HomeModel GetProductFromMenu(int page, int LevelMenu, int Id, string TitleMenu, int MenuId1, int MenuId2, int MenuId3)
        {
            homeModel.TotalRecord = pagingBIZ.ProductCountPagingById(Id, LevelMenu);

            if (homeModel.TotalRecord > 0)
            {
                homeModel.ProductListModel = pagingBIZ.ProductPagingById(page, Id, LevelMenu);
            }
            homeModel.CurrentPage = page;
            homeModel.LevelMenu = LevelMenu;
            homeModel.ProductId = Id;
            homeModel.ProductFlag = 0;
            homeModel.TitleMenu = TitleMenu.Replace("-", " ");
            homeModel.MenuId1 = MenuId1;
            homeModel.MenuId2 = MenuId2;
            homeModel.MenuId3 = MenuId3;
            return homeModel;
        }



        public ActionResult About()
        {
            ViewBag.Message = "Your app description page.";

            return View();
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }


        public ActionResult PagingSearch(int? page, string nameSearch)
        {

            int currentPageIndex = page.HasValue ? page.Value : 1;

            if (nameSearch == null) 
            {
                nameSearch = " ";
            }

            homeModel.TotalRecord = pagingBIZ.spProductCountSearchByName(nameSearch);

            if (homeModel.TotalRecord > 0)
            {
                homeModel.ProductListModel = pagingBIZ.proDuctSearchByNme(nameSearch, currentPageIndex);
                homeModel.CurrentPage = currentPageIndex;
                homeModel.NameSearch = nameSearch;
                homeModel.TitleMenu = "Kết quả tìm kiếm với : " + nameSearch;
            }
            else {
                homeModel.TitleMenu = "Không tìm thấy sản phẩm với : " + nameSearch;
            }
            return PartialView("_PagingSearch", homeModel);
        }

        // rewriter url show product
        [HttpGet]
        public ActionResult GetProduct(int page, int LevelMenu, int Ids, string TitleMenu, int MenuId1, int MenuId2, int MenuId3, string NameP)
        {
            int PageIndex1 = page;
            int LevelMenu1 = LevelMenu;
            int Id1 = Ids;
            homeModel = GetProductFromMenu(PageIndex1, LevelMenu1, Id1, NameP, MenuId1, MenuId2, MenuId3);

            // get thong tin cua menu ...
            homeModel.ListSalePersonModel = salePersonBIZ.SalePersonSearch();


            List<Category_eventModel> listItemCate = categoryEventBIZ.Category_eventSearch();

            List<Category_eventModel> listItemCate2 = new List<Category_eventModel>();

            foreach (var catergoryEvent in listItemCate)
            {
                catergoryEvent.listEventModel = BIZ.EventSearchTitleById_ce(catergoryEvent.Id);
                listItemCate2.Add(catergoryEvent);

            }

            homeModel.ListCategoryEventModel = listItemCate2;

            //homeModel.EventListModel = BIZ.EventSearchTitleById_ce(2);

            //foreach(var eventItem in BIZ.EventSearchTitleById_ce(1)) {
            //    homeModel.EventListModel.Add(eventItem);

            //}

            homeModel.CusListModel = BIZ.EventSearchTitleById_ce(6);


            homeModel.MenuListModel = menuBIZ.GetAllMenu();

            homeModel.SaleListModel = BIZ.EventSearchSale(1);

            return View(homeModel);

        }

        // rewriter url show product
        public ActionResult GetProductByFlg1()
        {
            int Flag = 1;
            homeModel.TotalRecord = pagingBIZ.ProductSearchSaleCount(Flag);
            if (homeModel.TotalRecord > 0)
            {
                homeModel.ProductListModel = pagingBIZ.ProductSearchSale(1, Flag, 20);
                homeModel.CurrentPage = 1;
                homeModel.LevelMenu = 0;
                homeModel.ProductId = 0;
                homeModel.ProductFlag = Flag;
            }

            if (Flag == 1)
            {
                homeModel.TitleMenu = "Sản phẩm mới";
            }
            else if (Flag == 2)
            {
                homeModel.TitleMenu = "Sản phẩm khuyến mãi";
            }
            else if (Flag == 3)
            {
                homeModel.TitleMenu = "Sản phẩm bán chạy";
            }

            // get thong tin cua menu ...
            homeModel.ListSalePersonModel = salePersonBIZ.SalePersonSearch();


            List<Category_eventModel> listItemCate = categoryEventBIZ.Category_eventSearch();

            List<Category_eventModel> listItemCate2 = new List<Category_eventModel>();

            foreach (var catergoryEvent in listItemCate)
            {
                catergoryEvent.listEventModel = BIZ.EventSearchTitleById_ce(catergoryEvent.Id);
                listItemCate2.Add(catergoryEvent);

            }

            homeModel.ListCategoryEventModel = listItemCate2;

            //homeModel.EventListModel = BIZ.EventSearchTitleById_ce(2);

            //foreach(var eventItem in BIZ.EventSearchTitleById_ce(1)) {
            //    homeModel.EventListModel.Add(eventItem);

            //}

            homeModel.CusListModel = BIZ.EventSearchTitleById_ce(6);


            homeModel.MenuListModel = menuBIZ.GetAllMenu();

            homeModel.SaleListModel = BIZ.EventSearchSale(1);

            return View(homeModel);

        }

        public ActionResult GetProductByFlg2()
        {
            int Flag = 2;
            homeModel.TotalRecord = pagingBIZ.ProductSearchSaleCount(Flag);
            if (homeModel.TotalRecord > 0)
            {
                homeModel.ProductListModel = pagingBIZ.ProductSearchSale(1, Flag, 20);
                homeModel.CurrentPage = 1;
                homeModel.LevelMenu = 0;
                homeModel.ProductId = 0;
                homeModel.ProductFlag = Flag;
            }

            if (Flag == 1)
            {
                homeModel.TitleMenu = "Sản phẩm mới";
            }
            else if (Flag == 2)
            {
                homeModel.TitleMenu = "Sản phẩm khuyến mãi";
            }
            else if (Flag == 3)
            {
                homeModel.TitleMenu = "Sản phẩm bán chạy";
            }

            // get thong tin cua menu ...
            homeModel.ListSalePersonModel = salePersonBIZ.SalePersonSearch();


            List<Category_eventModel> listItemCate = categoryEventBIZ.Category_eventSearch();

            List<Category_eventModel> listItemCate2 = new List<Category_eventModel>();

            foreach (var catergoryEvent in listItemCate)
            {
                catergoryEvent.listEventModel = BIZ.EventSearchTitleById_ce(catergoryEvent.Id);
                listItemCate2.Add(catergoryEvent);

            }

            homeModel.ListCategoryEventModel = listItemCate2;

            //homeModel.EventListModel = BIZ.EventSearchTitleById_ce(2);

            //foreach(var eventItem in BIZ.EventSearchTitleById_ce(1)) {
            //    homeModel.EventListModel.Add(eventItem);

            //}

            homeModel.CusListModel = BIZ.EventSearchTitleById_ce(6);


            homeModel.MenuListModel = menuBIZ.GetAllMenu();

            homeModel.SaleListModel = BIZ.EventSearchSale(1);

            return View(homeModel);

        }

        public ActionResult GetProductByFlg3()
        {
            int Flag = 3;
            homeModel.TotalRecord = pagingBIZ.ProductSearchSaleCount(Flag);
            if (homeModel.TotalRecord > 0)
            {
                homeModel.ProductListModel = pagingBIZ.ProductSearchSale(1, Flag, 20);
                homeModel.CurrentPage = 1;
                homeModel.LevelMenu = 0;
                homeModel.ProductId = 0;
                homeModel.ProductFlag = Flag;
            }

            if (Flag == 1)
            {
                homeModel.TitleMenu = "Sản phẩm mới";
            }
            else if (Flag == 2)
            {
                homeModel.TitleMenu = "Sản phẩm khuyến mãi";
            }
            else if (Flag == 3)
            {
                homeModel.TitleMenu = "Sản phẩm bán chạy";
            }

            // get thong tin cua menu ...
            homeModel.ListSalePersonModel = salePersonBIZ.SalePersonSearch();


            List<Category_eventModel> listItemCate = categoryEventBIZ.Category_eventSearch();

            List<Category_eventModel> listItemCate2 = new List<Category_eventModel>();

            foreach (var catergoryEvent in listItemCate)
            {
                catergoryEvent.listEventModel = BIZ.EventSearchTitleById_ce(catergoryEvent.Id);
                listItemCate2.Add(catergoryEvent);

            }

            homeModel.ListCategoryEventModel = listItemCate2;

            //homeModel.EventListModel = BIZ.EventSearchTitleById_ce(2);

            //foreach(var eventItem in BIZ.EventSearchTitleById_ce(1)) {
            //    homeModel.EventListModel.Add(eventItem);

            //}

            homeModel.CusListModel = BIZ.EventSearchTitleById_ce(6);


            homeModel.MenuListModel = menuBIZ.GetAllMenu();

            homeModel.SaleListModel = BIZ.EventSearchSale(1);

            return View(homeModel);

        }

        [HttpGet]
        public ActionResult TinTuc()
        {

            int Page1 = 1;
            Int32 Id = 1;
            //Int32 Page1 = Convert.ToInt32(Page); 
            newModel.TotalRecord = pagingBIZ.EventCountPagingById_ce(Id);

            if (newModel.TotalRecord > 0)
            {
                newModel.EventListModel = pagingBIZ.EventPagingById_ce(Page1, Id);
                newModel.CurrentPage = Page1;
                newModel.CategoryId = Id;
            }

            if (Id == 1)
            {
                newModel.Title = "Tin tức sự kiện";

            }

            if (Id == 2)
            {
                newModel.Title = "Dịch vụ";

            }

            if (Id == 8)
            {
                newModel.Title = "Đối tác";

            }

            homeModel.newModel = newModel;

            ///
            // get thong tin cua menu ...
            homeModel.ListSalePersonModel = salePersonBIZ.SalePersonSearch();


            List<Category_eventModel> listItemCate = categoryEventBIZ.Category_eventSearch();

            List<Category_eventModel> listItemCate2 = new List<Category_eventModel>();

            foreach (var catergoryEvent in listItemCate)
            {
                catergoryEvent.listEventModel = BIZ.EventSearchTitleById_ce(catergoryEvent.Id);
                listItemCate2.Add(catergoryEvent);

            }

            homeModel.ListCategoryEventModel = listItemCate2;

            //homeModel.EventListModel = BIZ.EventSearchTitleById_ce(2);

            //foreach(var eventItem in BIZ.EventSearchTitleById_ce(1)) {
            //    homeModel.EventListModel.Add(eventItem);

            //}

            homeModel.CusListModel = BIZ.EventSearchTitleById_ce(6);


            homeModel.MenuListModel = menuBIZ.GetAllMenu();

            homeModel.SaleListModel = BIZ.EventSearchSale(1);

            return View(homeModel);
        }

        [HttpGet]
        public ActionResult DoiTac()
        {

            int Page1 = 1;
            Int32 Id = 8;
            //Int32 Page1 = Convert.ToInt32(Page); 
            newModel.TotalRecord = pagingBIZ.EventCountPagingById_ce(Id);

            if (newModel.TotalRecord > 0)
            {
                newModel.EventListModel = pagingBIZ.EventPagingById_ce(Page1, Id);
                newModel.CurrentPage = Page1;
                newModel.CategoryId = Id;
            }

            if (Id == 1)
            {
                newModel.Title = "Tin tức sự kiện";

            }

            if (Id == 2)
            {
                newModel.Title = "Dịch vụ";

            }

            if (Id == 8)
            {
                newModel.Title = "Đối tác";

            }

            homeModel.newModel = newModel;

            ///
            // get thong tin cua menu ...
            homeModel.ListSalePersonModel = salePersonBIZ.SalePersonSearch();


            List<Category_eventModel> listItemCate = categoryEventBIZ.Category_eventSearch();

            List<Category_eventModel> listItemCate2 = new List<Category_eventModel>();

            foreach (var catergoryEvent in listItemCate)
            {
                catergoryEvent.listEventModel = BIZ.EventSearchTitleById_ce(catergoryEvent.Id);
                listItemCate2.Add(catergoryEvent);

            }

            homeModel.ListCategoryEventModel = listItemCate2;

            //homeModel.EventListModel = BIZ.EventSearchTitleById_ce(2);

            //foreach(var eventItem in BIZ.EventSearchTitleById_ce(1)) {
            //    homeModel.EventListModel.Add(eventItem);

            //}

            homeModel.CusListModel = BIZ.EventSearchTitleById_ce(6);


            homeModel.MenuListModel = menuBIZ.GetAllMenu();

            homeModel.SaleListModel = BIZ.EventSearchSale(1);

            return View(homeModel);
        }

        [HttpGet]
        public ActionResult DichVu()
        {

            int Page1 = 1;
            Int32 Id = 2;
            //Int32 Page1 = Convert.ToInt32(Page); 
            newModel.TotalRecord = pagingBIZ.EventCountPagingById_ce(Id);

            if (newModel.TotalRecord > 0)
            {
                newModel.EventListModel = pagingBIZ.EventPagingById_ce(Page1, Id);
                newModel.CurrentPage = Page1;
                newModel.CategoryId = Id;
            }

            if (Id == 1)
            {
                newModel.Title = "Tin tức sự kiện";

            }

            if (Id == 2)
            {
                newModel.Title = "Dịch vụ";

            }

            if (Id == 8)
            {
                newModel.Title = "Đối tác";

            }

            homeModel.newModel = newModel;

            ///
            // get thong tin cua menu ...
            homeModel.ListSalePersonModel = salePersonBIZ.SalePersonSearch();


            List<Category_eventModel> listItemCate = categoryEventBIZ.Category_eventSearch();

            List<Category_eventModel> listItemCate2 = new List<Category_eventModel>();

            foreach (var catergoryEvent in listItemCate)
            {
                catergoryEvent.listEventModel = BIZ.EventSearchTitleById_ce(catergoryEvent.Id);
                listItemCate2.Add(catergoryEvent);

            }

            homeModel.ListCategoryEventModel = listItemCate2;

            //homeModel.EventListModel = BIZ.EventSearchTitleById_ce(2);

            //foreach(var eventItem in BIZ.EventSearchTitleById_ce(1)) {
            //    homeModel.EventListModel.Add(eventItem);

            //}

            homeModel.CusListModel = BIZ.EventSearchTitleById_ce(6);


            homeModel.MenuListModel = menuBIZ.GetAllMenu();

            homeModel.SaleListModel = BIZ.EventSearchSale(1);

            return View(homeModel);
        }
    }
}
